import BiaofunRegionTwoLevel from '@/components/biaofun-region/biaofun-region-two-level.vue'; //组件
import lawBankTopBar from 'components/lawBankTopBar/lawBankTopBar' //组件
import {
	getPolicyDataList,
	getTaxList
} from '@/api/lawBank' //js
import {
	hightLightText
} from '@/utils/utils'
import {
	checkView
} from '@/api/checkView.js'
export default {
	components: {
		lawBankTopBar,
		BiaofunRegionTwoLevel
	},
	data() {
		return {
			title: '优惠政策',
			showPopup: false,
			tipsMsg: '今日免费次数已用完，请您充值成为会员，以享受更多精彩的功能和服务。',
			backgroundUrl: require('@/static/img/lawBank/topBar_bg_01.png'),
			searchText: '',
			scrollTop: 0,
			chooseTabId: 1, //分类选中下标
			tabsList: [{
				id: 1,
				nid: 1,
				name: '税收优惠政策'
			},
			{
				id: 2,
				nid: 2,
				name: '政府补助'
			}
			],
			sortList: [{
				id: 1,
				nid: 1,
				name: '热点法规'
			}, {
				id: 2,
				nid: 2,
				name: '中央法规'
			}, {
				id: 3,
				nid: 3,
				name: '地方法规'
			}, {
				id: 27,
				name: '海关综合文件'
			}, {
				id: 20,
				name: '国际跨境税收'
			}, {
				id: 28,
				name: '外汇文件'
			}, {
				id: 32,
				name: ' 12366热点问答'
			}, {
				nid: 4,
				name: '法规法条'
			}], //分类

			potencyList: [{
				id: '现行有效',
			}, {
				id: '部分失效/废止',
			}, {
				id: '全文失效/废止',
			}, {
				id: '已修订',
			}], //效力
			potencyIndex: -1, //效力选中下标
			indexType: -1, //税种选中下标
			taxTypeList: [], //税种类目
			keyword: '', //搜索关键字
			form: {
				keyword: '', //	否	string	搜索字段
				city_code: '', //	否	string	城市编码
				policy_cate_id: '',
				xiaoli_id: '',
				status: '', //政府补助 2
			},
			query: {
				type: 1, //	是	string	类型:1=优惠政策,2=财税法规
				page: 1,
				limit: 10,
			},
			isLoading: false,
			loadMoreStatue: 'more',
			count: 0,
			lawList: [],
			isRefreshing: false,
			loadMoreStatus: 'more',
			regionName: [], //省市区名
			isSearch: false, //判断是否是高级搜索页跳转过来的
			isSearch1: false, //普通搜索
			isShowImg: true,
		};
	},
	methods: {

		// 高亮
		hightLightText(text, keyword) {
			return hightLightText(text, keyword)
		},
		// 搜索
		search() {
			this.lawList = [];
			this.form.keyword = this.keyword
			this.isSearch1 = this.keyword == '' ? false : true
			this.query.page = 1;
			this.isShowImg = false;
			this.title = this.form.keyword ? '搜索结果' : '优惠政策';
			this.getList()
		},

		//去高级搜索页面
		goHighSearch(type) {
			uni.removeStorageSync('searchQuery');
			uni.navigateTo({
				url: `/lawBank/highSearch/highSearch?type=${type}`
			})
		},

		//选择分类,重置部分参数
		chooseTab(item, index) {
			this.chooseTabId = item.id; //分类选中下标
			if (index == 0) {
				this.form.status = '';
				this.form.type = 1;
			} else {
				this.form.status = 2;
				this.form.type = '';
			}
			this.query.page = 1; //重置页码
			this.form.city_code = ''; //重置城市code码
			this.form.policy_cate_id = ''; //重置税种id
			this.form.xiaoli_id = ''; //重置效力id
			this.lawList = []; //重置列表
			this.indexType = -1; //重置税种下标
			this.potencyIndex = -1; //重置效力下标
			this.keyword = ''; //重置关键字
			this.form.keyword = ''; //重置关键字
			this.getList();
		},

		//选择省市
		changeRegion(res) {
			this.regionName = res;
			this.form.city_code = res[1].id;
			this.query.page = 1;
			this.getList();
		},
		//取消省市区选择
		changeRegions1() {
			this.regionName = '';
			this.form.city_code = '';
			this.query.page = 1;
			this.getList();
		},
		//税种选择
		taxTypeChange(res) {
			let index = res.detail.value;
			this.indexType = index;
			this.form.policy_cate_id = this.taxTypeList[index].id;
			this.query.page = 1;
			this.getList();
		},
		//税种取消选择
		taxTypeCancel() {
			this.indexType = -1;
			this.form.policy_cate_id = '';
			this.query.page = 1;
			this.getList();
		},
		//效力选择
		potencyChange(res) {
			this.potencyIndex = res.detail.value;
			this.form.xiaoli_id = this.potencyList[this.potencyIndex].id;
			this.query.page = 1;
			this.getList();
		},
		//效力取消选择
		potencyCancel() {
			this.potencyIndex = -1;
			this.form.xiaoli_id = '';
			this.query.page = 1;
			this.getList();
		},

		//请求列表数据
		getList() {
			if (this.query.page == 1) {
				this.dataList = [];
				this.isLoading = true;
			} else {
				this.loadMoreStatue = 'loading';
			}
			let queryData = { ...this.form, ...this.query }
			getPolicyDataList(queryData).then(res => {
				if (res.code == 1) {
					if (res.data.length > 0) {
						this.count = res.data[0].all_count;
					} else {
						this.count = 0;
					}
					if (this.query.page == 1) {
						this.lawList = [];
					}
					var newList = res.data;
					if (newList.length >= this.query.limit) {
						this.loadMoreStatus = 'more';
					} else {
						this.loadMoreStatus = 'noMore';
					}
					this.lawList = [...this.lawList, ...newList];
					this.isRefreshing = false;
				} else {
					this.$tools.showToast(res.msg);
					this.loadMoreStatus = 'noMore';
				}
			})
		},

		//下拉刷新
		reload() {
			this.query.page = 1;
			this.lawList = [];
			this.isRefreshing = true;
			this.getList()
		},

		//加载更多
		loadMore() {
			if (this.loadMoreStatus == 'more') {
				this.query.page++;
				this.getList()
			} else {
				this.$used.msg('没有更多了');
			}
		},

		//去詳情
		toInfo(id) {
			checkView({
				id
			}).then(res => {
				if (res.code == -100) {
					this.showPopup = true
				} else {
					uni.navigateTo({
						url: `../revenue/revenueInfo?id=${id}&type=1`
					})
				}
			})
		},


		//获取税种
		getTaxType() {
			getTaxList({}).then((res) => {
				if (res.code == 1) {
					this.taxTypeList = res.data;
				} else {
					this.$tools.showToast(res.msg);
				}
			})
				.catch((err) => {
					console.log('错误回调', err);
				});
		},



	},
	onReady() {
	},
	onLoad(e) {
		let { isSearch } = e
		if (isSearch) {
			this.isSearch = isSearch
			this.isShowImg = false
			let data = uni.getStorageSync('searchQuery')
			this.form = data
			this.title = '搜索结果'
			this.getList()
		} else {
			this.getList()
			this.getTaxType()
		}
	},
	onShow() {
	}

}